from .models import User
from rest_framework import serializers


class UserSer(serializers.Serializer):
    # id只允许读取
    id = serializers.IntegerField(read_only=True)
    username = serializers.CharField(max_length=50)
    password = serializers.CharField(max_length=50)

    def create(self, data):
        user = User()
        user.username = data.get('username')
        user.password = data.get('password')
        user.save()
        return user
